/** 数据操作函数 */
import {
  GOODS_ADD,
  GOODS_DEL,
  GOODS_EDIT,
  GOODS_ALL,
  GOODS_INIT
} from './goodsType'

// import {
//   findAll
// } from '../../api/goodsApi'

function goodsReducer(state = [], creator) {
  switch (creator.type) {
    case GOODS_INIT:
      console.log("初始化数据")
      // 1.请求react发送，传输数据进行同步
      // state = creator.data
      // 2.请求由reducer发送
      // let response = await findAll()
      // state = response.data
      // 3.请求creator发送，传输数据进行同步
      state = creator.data
      return state

    case GOODS_ADD:
      console.log("增加商品数据")
      return state

    case GOODS_DEL:
      console.log("删除商品数据")
      return state

    case GOODS_EDIT:
      console.log("编辑商品数据")
      return state

    case GOODS_ALL:
      console.log("查询全部商品数据")
      return state

    default:
      console.log("读取全部商品数据")
      return state
  }

}

export default goodsReducer
